const cheerio = require('cheerio')
const filterChapters = (html) => {
  var $ = cheerio.load(html)
  const courseData = []
  var chapters = $('.chapter')
  chapters.each(function() {
    var chapter = $(this)
    chapterTitle = chapter.find('strong').text()
    var videos = chapter.find('.video').children('li')
    chapterData = {
      chapterTitle: chapterTitle,
      videos: []
    }
    videos.each(function(item) {
      var video = $(this).find('.J-media-item')
      var videoTitle = video.text()
      var id = video.attr('href').split('video/')[1]
      chapterData.videos.push({
        title: videoTitle,
        id: id
      })
    })
    courseData.push(chapterData)
  })
  console.log(courseData, 123)
  return courseData

}

module.exports = filterChapters